/**
 * 补发单管理相关js文件
 */
// 补发单Datatable
var waitVerify; // dataTable
var tableUrl = "";
var quickSearchText = ""; // 快速查询
var btnAdvSearchflg = false; // 高级查询是否点击标识

var searchCondition = {};

turn_on_iCheck = function(domElement) {
    return $('input[type="checkbox"],input[type="radio"]', domElement).iCheck({
        checkboxClass : 'icheckbox_flat-red',
        radioClass : 'iradio_flat-red'
    });
};

/**
 * 页面初期化
 */
$(document).ready(function() {
	var fromother = "n";
    if(window.top.window.$("#orderCode").val() !=""){
        fromother = "y";
        quickSearchText = window.top.window.$("#orderCode").val()
        window.top.window.$("#orderCode").val("");
        $('#quickSearch').val(quickSearchText);
    }
	/**
	 * 默认待审核显示 初始化时传个空字符串
	 */
	 showWaitVerifyTab();
	
	$("#waitVerify").tooltip({
        selector: ".tooltip-column-detail",
        container: "body",
        title: function() {
            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                return $(this).text();
            }
        }
    });

	// 初始化物流公司
	setLogisticsCompany();

	// 日期控件初始化，并且隐藏
	$('.panel-default .datetimepicker-default').datetimepicker();
	$(".panel-default .input-group-addon").hide();
	// 待审核数字,待发货数字,已完成数字,已取消数字
	getCounts();
	// 初始化店铺信息
	setShopValue();
	// 初始化省列表
	getProvList();
	//按钮控制
	setPageElementStatus("resend_list_page");

	// 绑定事件
	/**
	 * 项目列表选择事件
	 */
	$("#prjId").change(function(e) {
		// 项目ID
		var prjId = encodeURI(encodeURI($(this).val()));
	});

	// 初始化补发单表格（默认待审核）
	function showWaitVerifyTab(url) {
		var tebType = false;
		if(url == "getCompleteTable"){
			tebType = true;
		}
		if (url != null && url != "" && url != undefined) {
			tableUrl = url;
		} else {
			tableUrl = "getWaitVerifyTable";
		}
//		turn_on_iCheck($(".tab-content"));
		if(!$.fn.DataTable.isDataTable('#waitVerify')){
			waitVerify = $("#waitVerify").DataTable({
			    "processing" : true,
			    "serverSide" : true,
			    "lengthMenu" : [ [ 10, 25, 50, 100 , 500 , 1000 ], [ 10, 25, 50, 100 , 500 , 1000 ] ],
			    "dom" : '<"bottom"rtflp>',
			    "searching" : false,
			    "scrollX" : "100%",
	            "scrollXInner" : "110%",
	            "scrollY" : "410px",
	            "scrollCollapse": false,
			    "bPaginate" : true, // 是否显示（应用）分页器
			    "bInfo" : true, // 是否显示页脚信息，DataTables插件左下角显示记录数
			    "pagingType" : "full_numbers",
			    "deferRender" : true,
	            "fixedColumns" : {
	            	"leftColumns" : 0,
	                "rightColumns" : 1
	            },
			    "ajax" : {
			        "url" : "/afterSaleResend/" + tableUrl + ".action",
			        "data" : function(d) {
			        	if(window.top.window.$("#orderCode").val() !=""){
                            fromother = "y";
			        		quickSearchText = window.top.window.$("#orderCode").val()
			        	}
			            $('#quickSearch').val(quickSearchText)
	                    window.top.window.$("#orderCode").val("");
				        d.quickSearch = encodeURI($('#quickSearch').val());
				        d.formJson = encodeURI(JSON.stringify(searchCondition));
			        }
			    },
			    "tableTools" : {
				    "sRowSelect" : "bootstrap"
			    },
			    "columnDefs" : [ {
			    	"className" : "truncate-text tooltip-column-detail",
		            "targets" : [ 0 ]
		        },{
			    	"className" : "truncate-text tooltip-column-detail",
		            "targets" : [ 1 ]
		        },{
			    	"className" : "truncate-text tooltip-column-detail",
		            "targets" : [ 2 ]
		        },{
			    	"className" : "truncate-text tooltip-column-detail",
		            "targets" : [ 3 ]
		        },{
			    	"className" : "truncate-text tooltip-column-detail",
		            "targets" : [ 4 ]
		        },{
			    	"className" : "truncate-text tooltip-column-detail",
		            "targets" : [ 5 ]
		        },{
			    	"className" : "truncate-text tooltip-column-detail",
		            "targets" : [ 6 ]
		        },{
			    	"className" : "truncate-text tooltip-column-detail",
		            "targets" : [ 7 ]
		        },{
			    	"className" : "truncate-text tooltip-column-detail",
		            "targets" : [ 8 ]
		        },{
			    	"className" : "truncate-text tooltip-column-detail",
		            "targets" : [ 9 ]
		        },{
		        	"className" : "truncate-text tooltip-column-detail",
		            "targets" : [ 10 ],
		            "visible" : tebType
		        },{
			    	"className" : "truncate-text tooltip-column-detail",
		            "targets" : [ 11 ]
		        },{
		            "targets" : [ 12 ]
		        } ],
			    "columns" : [ {
			        "data" : "chk",
			        "orderable" : false
			    }, {
			        "data" : "resendStatus",// 显示中文状态
			        "orderable" : false,
			        "render" : function(data, type, row, meta) {
				        if (row.resendStatus == "a") {
					        return "登记";
				        } else if (row.resendStatus == "f") {
					        return "审核";
				        } else if (row.resendStatus == "z") {
					        return "完成";
				        } else if (row.cancelStatus == "y") {
					        return "取消";
				        }
			        }
			    }, {
			        "data" : "cancelStatus",
			        "orderable" : false,
			        "render" : function(data, type, row, meta) {
				        if (row.cancelStatus == "n") {
					        return "";
				        } else if (row.cancelStatus == "y") {
					        return "已取消";
				        }
			        }
			    }, {
			        "data" : "resendCode",
			        "orderable" : false
			    }, {
			        "data" : "sourceCode",
			        "orderable" : false
			    }, {
			        "data" : "ecTradeCode",
			        "orderable" : false
			    }, {
			        "data" : "shopName",
			        "orderable" : false
			    }, {
			        "data" : "buyerNick",
			        "orderable" : false
			    }, {
			        "data" : "storName",
			        "orderable" : false
			    }, {
				    "data" : "createTime"
			    },  {
				    "data" : "finishTime"
			    },{
				    "data" : "paidDate"
			    }, {
			        "data" : "resendReasonName",
			        "orderable" : false
			    }, {
			        "data" : "operation",
			        "orderable" : false
			    } ],
			    "order" : [ [ 9, "desc" ] ],
			}).on('draw.dt',  function() {
		     	//解决因滚动条导致的列对不齐问题
		        $(".dataTables_scrollBody").css("overflow-y","overlay");
		        $(".DTFC_RightBodyLiner").css("overflow-y","hidden");
		        /* turn_on_iCheck($(".tab-content"));
	            $("#chkAlla").on("ifChanged", function() {
	                if ($("#chkAlla").is(":checked")) {
	                    $("#waitVerify").find(".icheck").iCheck("check");
	                } else {
	                    $("#waitVerify").find(".icheck").iCheck("uncheck");
	                }
	            });*/
		         
		     });
		}else{
		    var optionData = waitVerify.settings()[0].ajax.data;
		    optionData = function(d){
		    	d.quickSearch = encodeURI($('#quickSearch').val());
		        d.formJson = encodeURI(JSON.stringify(searchCondition));
		    }
//		    
		    waitVerify.settings()[0].ajax.url = "/afterSaleResend/" + tableUrl + ".action";
		    waitVerify.settings()[0].ajax.data = optionData;
		    waitVerify.ajax.reload();
		}
	}
	;

	// 重新加载dataTable的数据
	function refreshWaitVerifyData(url) {
		var dttable;
//		if ($('#waitVerify').hasClass('dataTable')) {
//			dttable = $('#waitVerify').dataTable();
//			dttable.fnDestroy(); // 还原初始化了的datatable
//			dttable.fnClearTable(); // 清空一下table
//		}
		showWaitVerifyTab(url);
	}

	/* 待审批 */
	$("#waitVerifyA").on('show.bs.tab', function(e) {
		$("#auditing").show();
		$("#compulsoryAudit").show();
		refreshWaitVerifyData("getWaitVerifyTable");
	});
	/* 待发货 */
	$("#waitshipped").on('show.bs.tab', function(e) {
		$("#auditing").hide();
		$("#compulsoryAudit").hide();
		refreshWaitVerifyData("getWaitDeliverTable");
	});
	/* 已完成 */
	$("#complete").on('show.bs.tab', function(e) {
		$("#auditing").hide();
		$("#compulsoryAudit").hide();
		refreshWaitVerifyData("getCompleteTable");
	});
	/* 已取消 */
	$("#cancel").on('show.bs.tab', function(e) {
		$("#auditing").hide();
		$("#compulsoryAudit").hide();
		refreshWaitVerifyData("getCancalTable");
	});

    if (fromother=="y"){
        if ($("#waitingNum").text()!="0" && $("#waitingNum").text()!=null && $("#waitingNum").text()!= "" && $("#waitingNum").text()!=undefined){
            $("#myTab li:eq(5) a").tab('show')
        } else if ($("#waitingNum1").text()!="0" && $("#waitingNum").text()!=null && $("#waitingNum").text()!= "" && $("#waitingNum").text()!=undefined){
            $("#myTab li:eq(4) a").tab('show')
        } else if ($("#waitingNum2").text()!="0" && $("#waitingNum").text()!=null && $("#waitingNum").text()!= "" && $("#waitingNum").text()!=undefined){
            $("#myTab li:eq(3) a").tab('show')
        } else if ($("#waitingNum3").text()!="0" && $("#waitingNum").text()!=null && $("#waitingNum").text()!= "" && $("#waitingNum").text()!=undefined){
            $("#myTab li:eq(2) a").tab('show')
        } else {
            showWaitVerifyTab();
		}
    } else {
        showWaitVerifyTab();
	}

	// 补发单新增
	function ifrAdd(btnObj) {
		window.top.window.returnCustomModalDialog();
		var btnText = $.trim($(btnObj).text());
		var btnType;
		if (btnText == "查看") {
			var btnType = "check";
			$("#btnSave").hide();
		}
		if (btnText == "修改") {
			var btnType = "edit";
			$("#btnSave").show();
		}
		var resendId = $(btnObj).attr("resendId");
		var orderId = $(btnObj).attr("orderid");
		var iframeSrc = "./views/aftersale/resend/addAfterSaleResend.html?resOrderId=" + orderId + "&btnType=" + btnType + "&resendId=" + resendId;
		$("#ifmSysRefundDetail").attr("src", iframeSrc);
		$("#btnSave").unbind("click").bind("click", function() {
			// 调用子页面的保存方法
			window.top.frames["ifmSysRefundDetail"].window.saveResend(window.top.frames["ifmSysRefundDetail"].contentWindow);
		});
		var sysRefundDetailDialog = window.top.window.borrowCustomModalDialog($("#modalResendDetail"));
		sysRefundDetailDialog.on('hide.bs.modal', function() {
			// 父窗体归还本页的编辑对话框
			window.top.window.returnCustomModalDialog();
		});
		sysRefundDetailDialog.modal({
		    show : true,
		    backdrop : 'static'
		});
		// }
	}

	// 刷新

	$("#refresh").on('click', function() {
	    $('#quickSearch').val("");
	    quickSearch = "";
	    $("#advSearchReset").click();
	    searchCondition = {};
	    if (!$("#advSearchPanel").is(":hidden")){
	        $("#btnAdvSearch").click();   
	    }  
		refresh();
	})

	/*
	 * 刷新方法
	 */
	function refresh() {
		$("div .active").each(function() {
			switch ($(this).attr("id")) {
			case "waitVerifyA": // 待审核
				refreshWaitVerifyData("getWaitVerifyTable");
				break;
			case "waitshipped": // 待发货
				refreshWaitVerifyData("getWaitDeliverTable");
				break;
			case "complete": // 已完成
				refreshWaitVerifyData("getCompleteTable");
				break;
			case "cancel": // 已取消
				refreshWaitVerifyData("getCancalTable");
				break;
			default:
				break;
			}
		});
		getCounts();
	}
	/*
	 * 快速查询按钮
	 */
	$('#btnQuickSearch').click(function() {
		quickSearchText = $('#quickSearch').val();

		refresh();
	});
	
	/**
     * 搜索框的回车事件
     */ 
    $('#quickSearch').keydown(function(e){
        if(e.keyCode==13 && $('#btnQuickSearch').is(":visible")){
            $("#btnQuickSearch").click();
        }
    });

	/*
	 * 高级检索按钮点击
	 */
	$("#btnAdvSearch").click(function() {
		btnAdvSearchflg = true;
		if ($("#advSearchPanel").is(":hidden")) {
			$("#btnQuickSearch").hide();
            $("#advSearchPanel").show();
			$(this).children("i:eq(0)").removeClass("fa-angle-double-down");
			$(this).children("i:eq(0)").addClass("fa-angle-double-up");
		} else {
			$("#advSearchPanel").hide();
            $("#btnQuickSearch").show();
			$(this).children("i:eq(0)").removeClass("fa-angle-double-up");
			$(this).children("i:eq(0)").addClass("fa-angle-double-down");
		}

	});
//	$("#advSearchPanel").click(function() {
//		btnAdvSearchflg = true;
//	})
//	/**
//	 * body点击的时候高级检索收回
//	 */
//	$("body").click(function(e) {
//		if (btnAdvSearchflg == true) {
//			btnAdvSearchflg = false;
//		} else {
//			$("#advSearchPanel").hide();
//			$("#btnQuickSearch").show();
//			$("#btnAdvSearch").children("i:eq(0)").removeClass("fa-angle-double-up");
//			$("#btnAdvSearch").children("i:eq(0)").addClass("fa-angle-double-down");
//		}
//	});

	/*
	 * 高级查询中的时间类型变更的时候，开始时间，截止日期的控件赋值，显示，不显示
	 */
	$("#dateType").bind("change", function() {
		switch (this.value) {
		case "createTime": //
			$("#startTime1").show();
			$("#startTime2").hide();
			$("#startTime3").hide();
			$("#startTime4").hide();
			$("#orderTimeS").val("");
			$("#hidorderTimeS").val("");
			$("#paidDateS").val("");
			$("#hidpaidDateS").val("");
			$("#shipTimeS").val("");
			$("#hidshipTimeS").val("");
			$("#paidTimeS").val("");
			$("#hidpaidTimeS").val("");

			$("#endTime1").show();
			$("#endTime2").hide();
			$("#endTime3").hide();
			$("#endTime4").hide();
			$("#orderTimeE").val("");
			$("#hidorderTimeE").val("");
			$("#paidDateE").val("");
			$("#hidpaidDateE").val("");
			$("#shipTimeE").val("");
			$("#hidshipTimeE").val("");
			$("#paidTimeE").val("");
			$("#hidpaidTimeE").val("");
			$(".input-group-addon").show();
			break;
		case "apprTime": //
			$("#startTime1").hide();
			$("#startTime2").show();
			$("#startTime3").hide();
			$("#startTime4").hide();
			$("#orderTimeS").val("");
			$("#hidorderTimeS").val("");
			$("#paidDateS").val("");
			$("#hidpaidDateS").val("");
			$("#shipTimeS").val("");
			$("#hidshipTimeS").val("");
			$("#paidTimeS").val("");
			$("#hidpaidTimeS").val("");

			$("#endTime1").hide();
			$("#endTime2").show();
			$("#endTime3").hide();
			$("#endTime4").hide();
			$("#orderTimeE").val("");
			$("#hidorderTimeE").val("");
			$("#paidDateE").val("");
			$("#hidpaidDateE").val("");
			$("#shipTimeE").val("");
			$("#hidshipTimeE").val("");
			$("#paidTimeE").val("");
			$("#hidpaidTimeE").val("");
			$(".input-group-addon").show();
			break;
		case "finishTime": //
			$("#startTime1").hide();
			$("#startTime2").hide();
			$("#startTime3").show();
			$("#startTime4").hide();
			$("#orderTimeS").val("");
			$("#hidorderTimeS").val("");
			$("#paidDateS").val("");
			$("#hidpaidDateS").val("");
			$("#shipTimeS").val("");
			$("#hidshipTimeS").val("");
			$("#paidTimeS").val("");
			$("#hidpaidTimeS").val("");

			$("#endTime1").hide();
			$("#endTime2").hide();
			$("#endTime3").show();
			$("#endTime4").hide();
			$("#orderTimeE").val("");
			$("#hidorderTimeE").val("");
			$("#paidDateE").val("");
			$("#hidpaidDateE").val("");
			$("#shipTimeE").val("");
			$("#hidshipTimeE").val("");
			$("#paidTimeE").val("");
			$("#hidpaidTimeE").val("");
			$(".input-group-addon").show();
			break;
		case "paidDate": //
			$("#startTime1").hide();
			$("#startTime2").hide();
			$("#startTime3").hide();
			$("#startTime4").show();
			$("#orderTimeS").val("");
			$("#hidorderTimeS").val("");
			$("#paidDateS").val("");
			$("#hidpaidDateS").val("");
			$("#shipTimeS").val("");
			$("#hidshipTimeS").val("");
			$("#paidTimeS").val("");
			$("#hidpaidTimeS").val("");

			$("#endTime1").hide();
			$("#endTime2").hide();
			$("#endTime3").hide();
			$("#endTime4").show();
			$("#orderTimeE").val("");
			$("#hidorderTimeE").val("");
			$("#paidDateE").val("");
			$("#hidpaidDateE").val("");
			$("#shipTimeE").val("");
			$("#hidshipTimeE").val("");
			$("#paidTimeE").val("");
			$("#hidpaidTimeE").val("");
			$(".input-group-addon").show();
			break;
		default:
			$("#orderTimeS").val("");
			$("#hidorderTimeS").val("");
			$("#paidDateS").val("");
			$("#hidpaidDateS").val("");
			$("#shipTimeS").val("");
			$("#hidshipTimeS").val("");
			$("#paidTimeS").val("");
			$("#hidpaidTimeS").val("");
			$("#orderTimeE").val("");
			$("#hidorderTimeE").val("");
			$("#paidDateE").val("");
			$("#hidpaidDateE").val("");
			$("#shipTimeE").val("");
			$("#hidshipTimeE").val("");
			$("#paidTimeE").val("");
			$("#hidpaidTimeE").val("");
			$(".input-group-addon").hide();
			break;
		}
	});

	$('#chkAlla').on('click', function() {
		// .is(':checked')
		if ($('#chkAlla').is(':checked')) {
			$("#waitVerify :input[name='chkItem']").prop("checked", true);
		} else {
			$("#waitVerify :input[name='chkItem']").prop("checked", false);
		}
		;
	})

	/**
	 * 网店变化的时候，发货仓库的值要变化
	 */
	$('#shopId').on('change', function() {

		if ($("#shopId").val() == "") {
			$("#storIdNew").val("");
			$("#storIdNew option").remove();
			$("#storIdNew").append("<option value=''>请选择</option>");
			return;
		}

		// 获取仓库列表的请求
		$.ajax({
		    type : "GET",
		    url : "/stor/getStorageByShopId.action?shopId=" + $("#shopId").val(),
		    contentType : "application/json;charset=utf-8",
		    dataType : "json",
		    async : false,// 同步
		    success : function(data) {
			    if (data.result == "success") {
				    $("#storIdNew option").remove();
				    $("#storIdNew").append("<option value=''>请选择</option>");
				    $.each(data.data, function(n, value) {
					    $('#storIdNew').append("<option value='" + value.storId + "'>" + value.storName + "</option>");
				    });
			    } else {
				    window.top.window.showModalAlert(data.msg);
			    }
		    },
		    error : function(XMLHttpRequest, textStatus) {
			    if (XMLHttpRequest.status == 500) {
				    var result = eval("(" + XMLHttpRequest.responseText + ")");
				    alert(result.errorObject.errorText);
			    }
		    }
		});
	});

	/**
	 * 省变化的时候，市，区的值要变化
	 */
	$('#provName').on('change', function() {

		window.top.window.$("#cityName").val("");
		window.top.window.$("#distName").val("");
		getCtiyList();

	});
	/**
	 * 市变化的时候，区的值要变化
	 */
	$('#cityName').on('change', function() {

		window.top.window.$("#distName").val("");
		getDistList();

	});

	/*
	 * 查看点击事件
	 */
	$('#examine').on('click', function() {
		$(this).parents("#newForm").find("input").attr("readonly", "true");// .
		$(this).parents("#newForm").find("select").attr("readonly", "true");//
		$(this).parents("#newForm").find("#examine").hide();// 按钮隐藏
		$(this).parents("#newForm").find("#cancelBtn").hide();// 按钮隐藏
		$(this).parents("#newForm").find("#addNoOrder").hide();// 按钮隐藏
		$(this).parents("#newForm").find("#addOrder").hide();// 按钮隐藏
		$(this).parents("#newForm").find("#addGift").hide();// 按钮隐藏
//		$(this).parents("#newForm").find("#actionType").val("detail");// 按钮隐藏
	})

	/*
	 * model仓库列表请求接口方法
	 */
	function getStorage(id) {
		$.ajax({
		    type : "GET",
		    url : "/stor/getStorageByShopId.action?shopId=" + id,
		    contentType : "application/json;charset=utf-8",
		    dataType : "json",
		    async : false,// 同步
		    success : function(data) {
			    if (data.result == "success") {
				    window.top.window.$("#storName option").remove();
				    window.top.window.$("#storName").append("<option value=''>请选择</option>");
				    $.each(data.data, function(n, value) {
					    window.top.window.$('#storName').append("<option value='" + value.storId + "'>" + value.storName + "</option>");
				    });
			    } else {
				    window.top.window.showModalAlert(data.msg);
			    }
		    },
		    error : function(XMLHttpRequest, textStatus) {
			    if (XMLHttpRequest.status == 500) {
				    var result = eval("(" + XMLHttpRequest.responseText + ")");
				    alert(result.errorObject.errorText);
			    }
		    }
		});
	}
	/*
	 * model补发原因类型请求接口方法
	 */
	function getDictList() {
		$.ajax({
		    type : "GET",
		    url : "/dictionary/dictList.action",
		    contentType : "application/json;charset=utf-8",
		    dataType : "json",
		    async : false,// 同步
		    success : function(data) {
			    if (data.result == "success") {
				    window.top.window.$("#ResendReasonType option").remove();
				    window.top.window.$("#ResendReasonType").append("<option value=''>请选择</option>");
				    $.each(data.data, function(n, value) {
					    window.top.window.$('#ResendReasonType').append("<option value='" + value.dictId + "'>" + value.dictName + "</option>");
				    });
			    } else {
				    window.top.window.showModalAlert(data.msg);
			    }
		    },
		    error : function(XMLHttpRequest, textStatus) {
			    if (XMLHttpRequest.status == 500) {
				    var result = eval("(" + XMLHttpRequest.responseText + ")");
				    alert(result.errorObject.errorText);
			    }
		    }
		});
	}
	/*
	 * model 获取省信息
	 */
	function getProvList() {
		// 省 初期化
		$.ajax({
		    type : "GET",
		    url : "/area/getProvList.action",
		    contentType : "application/json;charset=utf-8",
		    dataType : "json",
		    async : true,// 同步
		    success : function(data) {
			    if (data.result == "success") {
				    $("#provName option").remove();
				    $("#provName").append("<option value=''>请选择</option>");
				    $.each(data.data, function(n, value) {
					    $('#provName').append("<option value='" + value.areaCode + "'>" + value.areaName + "</option>");
				    });

			    } else {
				    window.top.window.showModalAlert(data.msg);
			    }
		    },
		    error : function(XMLHttpRequest, textStatus) {
			    if (XMLHttpRequest.status == 500) {
				    var result = eval("(" + XMLHttpRequest.responseText + ")");
				    alert(result.errorObject.errorText);
			    }
		    }
		});
	}
	/*
	 * model 获取市列表
	 */
	function getCtiyList() {
		$.ajax({
		    type : "GET",
		    url : "/area/getCityList.action?provId=" + window.top.window.$("#provName").val(),
		    contentType : "application/json;charset=utf-8",
		    dataType : "json",
		    async : false,// 同步
		    success : function(data) {
			    if (data.result == "success") {
				    window.top.window.$("#cityName option").remove();
				    window.top.window.$("#cityName").append("<option value=''>请选择</option>");
				    window.top.window.$("#cityName option").remove();
				    window.top.window.$("#cityName").append("<option value=''>请选择</option>");
				    $.each(data.data, function(n, value) {
					    window.top.window.$('#cityName').append("<option value='" + value.areaCode + "'>" + value.areaName + "</option>");
				    });
			    } else {
				    window.top.window.showModalAlert(data.msg);
			    }
		    },
		    error : function(XMLHttpRequest, textStatus) {
			    if (XMLHttpRequest.status == 500) {
				    var result = eval("(" + XMLHttpRequest.responseText + ")");
				    alert(result.errorObject.errorText);
			    }
		    }
		});
	}
	/*
	 * model 获取区列表
	 */
	function getDistList() {
		$.ajax({
		    type : "GET",
		    url : "/area/getDistList.action?cityId=" + window.top.window.$("#cityName").val(),
		    contentType : "application/json;charset=utf-8",
		    dataType : "json",
		    async : false,// 同步
		    success : function(data) {
			    if (data.result == "success") {
				    window.top.window.$("#distName option").remove();
				    window.top.window.$("#distName").append("<option value=''>请选择</option>");
				    $.each(data.data, function(n, value) {
					    window.top.window.$('#distName').append("<option value='" + value.areaCode + "'>" + value.areaName + "</option>");
				    });
			    } else {
				    window.top.window.showModalAlert(data.msg);
			    }
		    },
		    error : function(XMLHttpRequest, textStatus) {
			    if (XMLHttpRequest.status == 500) {
				    var result = eval("(" + XMLHttpRequest.responseText + ")");
				    alert(result.errorObject.errorText);
			    }
		    }
		});
	}

	// 高级搜索“提交”按钮点击
	$("#advSearchSubmit").click(function(e) {
		// 记录高级查询的检索条件
		var shopName;
		if ($("#shopId").find("option:selected").text() == "请选择") {
			shopName = "";
		} else {
			shopName = $("#shopId").find("option:selected").text();
		}

		var storeName;
		if ($('#storIdNew').find("option:selected").text() == "请选择") {
			storeName = "";
		} else {
			storeName = $('#storIdNew').find("option:selected").text();
		}

		var lgstName;
		if ($('#lgstId').find("option:selected").text() == "请选择") {
			lgstName = "";
		} else {
			lgstName = $('#lgstId').find("option:selected").text();
		}
		quickSearchText = $('#quickSearch').val();
		setHidValue("frmAdvSearch");
		searchCondition = { // 高级检索
		    "queryOrderCode" : $('#orderCode').val(), // 订单编号（来源单编号）
		    "resendId" : "", // 补发单ID
		    "queryShopName" : shopName, // 店铺ID
		    "queryDateType" : $('#dateType').val(), // 时间类型
		    "queryDateStart" : "", // 开始时间
		    "queryDateEnd" : "", // 结束时间
		    "queryStorName" : storeName, // 发货仓库
		    "queryLgstName" : lgstName, // 补发物流公司
		};

		if ($('#hidorderTimeS').val() != "" && $('#hidorderTimeE').val() != null) {
			searchCondition.queryDateStart = $('#hidorderTimeS').val();
			searchCondition.queryDateEnd = $('#hidorderTimeE').val();
		} else if ($('#hidpaidDateS').val() != "" && $('#hidpaidDateE').val() != null) {
			searchCondition.queryDateStart = $('#hidpaidDateS').val();
			searchCondition.queryDateEnd = $('#hidpaidDateE').val();
		} else if ($('#hidshipTimeS').val() != "" && $('#hidshipTimeE').val() != null) {
			searchCondition.queryDateStart = $('#hidshipTimeS').val();
			searchCondition.queryDateEnd = $('#hidshipTimeE').val();
		} else if ($('#hidpaidTimeS').val() != "" && $('#hidpaidTimeE').val() != null) {
			searchCondition.queryDateStart = $('#hidpaidTimeS').val();
			searchCondition.queryDateEnd = $('#hidpaidTimeE').val();
		}

		refresh();
//		searchCondition = {};
//		$("#advSearchPanel").hide();
//		$("#btnAdvSearch").children("i:eq(0)").removeClass("fa-angle-double-up");
//		$("#btnAdvSearch").children("i:eq(0)").addClass("fa-angle-double-down");

	});

	/**
	 * 初始化物流公司
	 */
	function setLogisticsCompany() {
		// 物流公司 初期化
		$.ajax({
		    type : "GET",
		    url : "/lgst/getLgstByProjectId.action?projectId=" + window.top.window.$("#projectSwitch").val(),
		    contentType : "application/json;charset=utf-8",
		    dataType : "json",
		    async : false,// 同步
		    success : function(data) {
			    if (data.result == "success") {
				    $("#lgstId option").remove();
				    $("#lgstId").append("<option value=''>请选择</option>");
				    $.each(data.data, function(n, value) {
					    $('#lgstId').append("<option value='" + value.lgstId + "'>" + value.lgstName + "</option>");
				    });
				    $("#lgstIdNew option").remove();
				    $("#lgstIdNew").append("<option value=''>请选择</option>");
				    $.each(data.data, function(n, value) {
					    $('#lgstIdNew').append("<option value='" + value.lgstId + "'>" + value.lgstName + "</option>");
				    });
			    } else {
				    window.top.window.showModalAlert(data.msg);
			    }
		    },
		    error : function(XMLHttpRequest, textStatus) {
			    if (XMLHttpRequest.status == 500) {
				    var result = eval("(" + XMLHttpRequest.responseText + ")");
				    alert(result.errorObject.errorText);
			    }
		    }
		});
	}
	;

	/**
	 * 初始化店铺列表
	 * 
	 * @returns
	 */
	function setShopValue() {
		// 初始化店铺列表
		$.ajax({
		    type : "GET",
		    url : "/shop/unpagedShopList.action?prjId=" + window.top.window.$("#projectSwitch").val(),
		    contentType : "application/json;charset=utf-8",
		    dataType : "json",
		    async : false,// 同步
		    success : function(data) {
			    if (data.result == "success") {
				    $("#shopId option").remove();
				    $("#shopId").append("<option value=''>请选择</option>");
				    $.each(data.data, function(n, value) {
					    $('#shopId').append("<option value='" + value.shopId + "' shopType = '" + value.shopType + "'>" + value.shopName + "</option>");
				    });
			    } else {
				    window.top.window.showModalAlert(data.msg);
			    }
		    },
		    error : function(XMLHttpRequest, textStatus) {
			    if (XMLHttpRequest.status == 500) {
				    var result = eval("(" + XMLHttpRequest.responseText + ")");
				    alert(result.errorObject.errorText);
			    }
		    }
		});
	}

	/**
	 * 取得tab上面的数字
	 * 
	 * @returns
	 */
	function getCounts() {
		// 待处理数字,待卖家操作,待买家操作,已完成数字,已废弃数字
		$.ajax({
		    type : "GET",
		    url : "/afterSaleResend/queryStateCount.action",
		    data : {
		        "quickSearch" : encodeURI($('#quickSearch').val()),
		        "formJson" : encodeURI(JSON.stringify(searchCondition))
		    },
		    contentType : "application/json;charset=utf-8",
		    dataType : "json",
		    async : false,// 同步
		    success : function(data) {
			    if (data.result == "success") {
				    $("#waitingNum").html(data.countVerify);
				    $("#waitingNum1").html(data.countDeliver);
				    $("#waitingNum2").html(data.countComplete);
				    $("#waitingNum3").html(data.countCancal);

			    } else {
				    window.top.window.showModalAlert(data.msg);
			    }
		    },
		    error : function(XMLHttpRequest, textStatus) {
			    if (XMLHttpRequest.status == 500) {
				    var result = eval("(" + XMLHttpRequest.responseText + ")");
				    alert(result.errorObject.errorText);
			    }
		    }
		});
	}

	// 审核按钮点击事件
	$("#auditing").on('click', function() {
		var tableList = $("#waitVerify tbody input[type = checkbox]");
		var tableData;
		var resendIds = [];
		var errstr = "";
		for (var i = 0; i < tableList.length; i++) {
			if (tableList.get(i).checked) {
				var trNode = tableList.get(i).parentNode.parentNode;//.parentNode
				tableData = waitVerify.row(trNode).data();
				resendIds.push(tableData.resendId);
				if (tableData.lgstNo = null ||tableData.lgstNo == "") {
					errstr = errstr + "补发单" + + "没有设置快递单号！\r\n"
			    }
			}
		}
		if (errstr != "") {
			window.top.window.showModalAlert(errstr);
			return ;
		}
		if ($("#waitVerify tbody input[type = checkbox]:checked").length < 1) {
	        window.top.window.showModalAlert("请选择要审核的数据");
	    } else {
	        window.top.window.showModalConfirms("确定审核补发单吗？", function (){
	            auditResend(resendIds);
	        });
	    }
		/*auditResend(resendIds);*/
	});
	// 强制审核按钮点击事件
	$("#compulsoryAudit").on('click', function() {
		var tableList = $("#waitVerify tbody input[type = checkbox]");
		var tableData;
		var resendIds = [];
		for (var i = 0; i < tableList.length; i++) {
			if (tableList.get(i).checked) {
				var trNode = tableList.get(i).parentNode.parentNode;//.parentNode
				tableData = waitVerify.row(trNode).data();
				resendIds.push(tableData.resendId);
			}
		}
		if ($("#waitVerify tbody input[type = checkbox]:checked").length < 1) {
            window.top.window.showModalAlert("请选择要审核的数据");
        } else {
            window.top.window.showModalConfirm("是否执行强制审核操作？", function() {
    			var resendIdStr = encodeURI(resendIds.join(","))
    			var question = "1";
    			compulsoryAuditResend(resendIdStr,question);
            });
        }
	});
	/*
	 * 审核接口请求
	 */
	function auditResend(ids) {
		var loading = window.top.window.getIndexBusyOverlay();
		$.ajax({
		    type : "POST",
		    url : "/afterSaleResend/auditResend.action",
		    data : JSON.stringify(ids),
		    contentType : "application/json;charset=utf-8",
		    dataType : "json",
//		    async : true,// 同步
		    beforeSend:function(){
	            if(loading) {
	            	loading.settext("正在处理中，请稍后...");
	            }
	        },
		    success : function(data) {
		    	loading.remove();
			    if (data.result == "success") {
				    refresh();
			    } else {
			    	var regs = new RegExp(/\\n/,"g");
				    window.top.window.showModalAlertPretty(data.msg.replace(regs, "<br/>"));
			    }
		    },
		    error : function(XMLHttpRequest, textStatus) {
		    	loading.remove();
			    if (XMLHttpRequest.status == 500) {
				    var result = eval("(" + XMLHttpRequest.responseText + ")");
				    alert(result.errorObject.errorText);
			    }
		    }
		});
	}
	;
	/*
	 * 强制审核接口请求
	 */
	function compulsoryAuditResend(ids,question) {
		var loading = window.top.window.getIndexBusyOverlay();
		$.ajax({
		    type : "POST",
		    url : "/afterSaleResend/mandatoryAuditResend.action?resendIds=" + ids +"&question="+question,
		    data : JSON.stringify(ids),
		    contentType : "application/json;charset=utf-8",
		    dataType : "json",
//		    async : true,// 同步
		    beforeSend:function(){
	            if(loading) {
	            	loading.settext("正在处理中，请稍后...");
	            }
	        },
		    success : function(data) {
		    	loading.remove();
			    if (data.result == "success") {
			    	window.top.window.showScoMessage("ok", data.msg);
				    refresh();
//				    window.top.window.$(".modal-backdrop").removeClass();
			    } else {
			    	if(data.question !=undefined && data.question != null && data.question != ""){
			    	    var regs = new RegExp(/\\n/,"g");
				    	window.top.window.showModalConfirmHtml(data.question.replace(regs, "<br/>"), function (){
				    		compulsoryAuditResend(data.data,"0")
				    	});
			    	}else {
			    		var regs = new RegExp(/\\n/,"g");
					    window.top.window.showModalAlertPretty(data.msg.replace(regs, "<br/>"));
//			    		 window.top.window.showModalAlert(data.msg);
			    	}
			    }
			    window.top.window.$(".modal-backdrop").removeClass();
		    },
		    error : function(XMLHttpRequest, textStatus) {
		    	loading.remove();
			    if (XMLHttpRequest.status == 500) {
				    var result = eval("(" + XMLHttpRequest.responseText + ")");
				    alert(result.errorObject.errorText);
			    }
		    }
		});
	}
	;

	// 修改按钮点击事件
	operationEdit = function(btnObj) {
		if (btnObj) {
			var sysRefundId = $(btnObj).attr("resendid");
			if (!!sysRefundId) {
				btnText = $(btnObj).text();
				$('#editTitle').html(btnText + "补发单");
				ifrAdd(btnObj);
			}
		}
	};
	// 查看按钮点击事件
	operationCheck = function(btnObj) {
		var btnText;
		if (btnObj) {
			var sysRefundId = $(btnObj).attr("resendid");
			if (!!sysRefundId) {
				btnText = $(btnObj).text();
				$('#editTitle').html(btnText + "补发单");
				ifrAdd(btnObj);
			}
		}
	};
	
	
	// 删除按钮点击事件
	operationDelete = function(btnObj) {
		var loading = window.top.window.getIndexBusyOverlay();
		if (btnObj) {
			var afterSaleRefundId = $(btnObj).attr("resendid");
			if (!!afterSaleRefundId) {
				$.ajax({
				    type : "GET",
				    url : "/afterSaleResend/deleteResend.action",
				    data : {
					    "resendIds" : afterSaleRefundId
				    },
				    contentType : "application/json;charset=utf-8",
				    dataType : "json",
//				    async : true,// 同步
				    beforeSend:function(){
			            if(loading) {
			            	loading.settext("正在处理中，请稍后...");
			            }
			        },
				    success : function(data) {
				    	loading.remove();
					    if (data.result == "success") {
						    window.top.window.showScoMessage("ok", data.msg);
						    refresh();
					    } else {
						    window.top.window.showModalAlert(data.msg);
					    }
				    },
				    error : function(XMLHttpRequest, textStatus) {
				    	loading.remove();
					    if (XMLHttpRequest.status == 500) {
						    var result = eval("(" + XMLHttpRequest.responseText + ")");
						    alert(result.errorObject.errorText);
					    }
				    }
				});
			}
		}
	};
	// 取消按钮点击事件
	operationCancel = function(btnObj) {
		if (btnObj) {
			var afterSaleRefundId = $(btnObj).attr("resendid");
			if (!!afterSaleRefundId) {
				var loading = window.top.window.getIndexBusyOverlay();
				$.ajax({
				    type : "GET",
				    url : "/afterSaleResend/cancelResend.action",
				    data : {
					    "resendId" : afterSaleRefundId
				    },
				    contentType : "application/json;charset=utf-8",
				    dataType : "json",
//				    async : true,// 同步
				    beforeSend:function(){
			            if(loading) {
			            	loading.settext("正在处理中，请稍后...");
			            }
			        },
				    success : function(data) {
				    	loading.remove();
					    if (data.result == "success") {
						    window.top.window.showScoMessage("ok", data.data);
						    refresh();
					    } else {
						    window.top.window.showModalAlert(data.msg);
					    }
				    },
				    error : function(XMLHttpRequest, textStatus) {
				    	loading.remove();
					    if (XMLHttpRequest.status == 500) {
						    var result = eval("(" + XMLHttpRequest.responseText + ")");
						    alert(result.errorObject.errorText);
					    }
				    }
				});
			}
		}
	};

});
